package com.speed_run.utils;
import java.time.LocalDate;
	
import java.time.YearMonth;
 	
import java.time.temporal.ChronoUnit;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class DateUtils {

    public static ArrayList<String> getPastdays(int intervals){
        ArrayList<String> pastDaysList = new ArrayList<>();
        for (int i = 0; i <intervals; i++) {
            pastDaysList.add(getPastDate(i));
        }
        return pastDaysList;
    }

    public static String getPastDate(int past) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) - past);
        Date today = calendar.getTime();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String result = format.format(today);
        return result;
    }

    public static  List<String> getDateListByTime(Long startTime, Integer type){
        List<String> list = new ArrayList<>();
        Date date = new Date(startTime);
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        LocalDate localDate = LocalDate.of(c.get(Calendar.YEAR),c.get(Calendar.MONTH)+1,c.get(Calendar.DAY_OF_MONTH));
        Integer length = 0;
        if(type == 0){
            for (int i = 0; i < 7; i++) {
                LocalDate _localDate =localDate.plus(i, ChronoUnit.DAYS);
                list.add(_localDate.toString());
            }
        }else{
            length = YearMonth.of(localDate.getYear(),localDate.getMonth()).lengthOfMonth();
            for (int i = 0; i < length; i++) {
                LocalDate _localDate =localDate.plus(i, ChronoUnit.DAYS);
                list.add(_localDate.toString());
            }
        }
        return list;
    }

    public static void main(String[] args) {

       /* Long a = 1509027308000l;
        Date date = new Date(a);
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        LocalDate localDate = LocalDate.of(c.get(Calendar.YEAR),c.get(Calendar.MONTH)+1,c.get(Calendar.DAY_OF_MONTH));
        LocalDate localDate1 =localDate.plus(1, ChronoUnit.DAYS);
        YearMonth y = YearMonth.of(localDate.getYear(),localDate.getMonth());
        System.out.println(y.lengthOfMonth());*/
        getDateListByTime(1506870606000l,1);
    }
   /* public static String getFetureDate(int past) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + past);
        Date today = calendar.getTime();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String result = format.format(today);
        Log.e(null, result);
        return result;
    }*/
}
